<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
    <link rel="stylesheet" href="/static/bootstrap-3.3.7-dist/css/bootstrap.css">
    <link rel="stylesheet" href="/static/font-awesome-4.7.0/css/font-awesome.min.css">
    <script src="/static/jQuery-3.3.1.js"></script>
    <script src="/static/bootstrap-3.3.7-dist/js/bootstrap.js"></script>
    <style>
        .media-object {
            height: 50px;
            width: 50px;
        }

        .media-spans {
            margin-top: 10px;
        }

        .media-spans span {
            padding-right: 10px;
        }
    </style>
</head>
<body>

<div class="container">
    <div class="row">
        <div>
            <nav class="navbar navbar-default">
                <div class="container-fluid">
                    <!-- Brand and toggle get grouped for better mobile display -->
                    <div class="navbar-header">
                        <a class="navbar-brand" href="#">小站点</a>
                    </div>

                    <!-- Collect the nav links, forms, and other content for toggling -->
                    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                        <ul class="nav navbar-nav">
                            <li class="active"><a href="#">首页 <span class="sr-only">(current)</span></a></li>
                            <li><a href="#">其它</a></li>
                        </ul>
                        <ul class="nav navbar-nav navbar-right">
                            {% if request.user.is_authenticated %}
                                <li class="dropdown">
                                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
                                       aria-haspopup="true" aria-expanded="false">{{ request.user.username }} <span
                                            class="caret"></span></a>
                                    <ul class="dropdown-menu">
                                        <li><a href="#">个人中心</a></li>
                                        <li><a href="#">内容管理</a></li>
                                        <li><a href="#">我的订单</a></li>
                                        <li role="separator" class="divider"></li>
                                        <li><a href="{% url 'logout' %}">退出</a></li>
                                    </ul>
                                </li>
                            {% else %}
                                <li><a href="{% url 'login' %}">登陆</a></li>
                                <li><a href="{% url 'register' %}">注册</a></li>
                            {% endif %}
                        </ul>
                    </div><!-- /.navbar-collapse -->
                </div><!-- /.container-fluid -->
            </nav>
        </div>

        <div class="col-md-4">
            <div class="panel panel-primary">
                <div class="panel-heading">分类1</div>
                <div class="panel-body">
                    分类的内容
                </div>
            </div>
            <div class="panel panel-success">
                <div class="panel-heading">分类专栏</div>
                <div class="panel-body">
                    分类 分类
                </div>
            </div>
            <div class="panel panel-warning">
                <div class="panel-heading">最新评论</div>
                <div class="panel-body">
                    评论
                </div>
            </div>

        </div>
        <div class="col-md-8">
            {% for article in articles %}
                <div class="media">
                    <h4>{{ article.title }}</h4>
                    <div class="media-left">
                        <a href="#">
                            <img class="media-object" src="/media/{{ article.blog.userinfo.avatar }}">
                        </a>
                    </div>
                    <div class="media-body">
                        {#                        {{ article.content|truncatechars:150}}#}
                        {{ article.content|truncatechars:150 }}...
                    </div>
                    <div class="media-spans">
                        <span><a href="/{{ article.blog.userinfo.username }}">{{ article.blog.userinfo.username }}</a></span>
                        <span>发布于: {{ article.create_time|date:'Y-m-d H:i:s' }}</span>
                        <span><i class="fa fa-comments-o" aria-hidden="true"></i><a href="#">{{ article.commit_num }}</a></span>
                        <span><i class="fa fa-thumbs-o-up" aria-hidden="true"></i><a href="#">{{ article.up_num }}</a></span>
                        <span><i class="fa fa-thumbs-o-down" aria-hidden="true"></i><a href="#">{{ article.down_num }}</a></span>
                    </div>
                </div>
                <hr>
            {% endfor %}

            <div class="navigation">
                <nav aria-label="Page navigation">
                    <ul class="pagination">
                        {% if articles.has_previous %}
                            <li>
                                <a href="{% url 'index' articles.previous_page_number %}" aria-label="Previous">
                                    <span aria-hidden="true">&laquo;</span>
                                </a>
                            </li>
                        {% else %}
                            <li><span aria-hidden="true" class="disabled">&laquo;</span></li>
                        {% endif %}

                        {% for pers in per_list %}
                            {% if page == pers.numerator %}
                                <li class="active"><a href="{% url 'index' pers.numerator %}">{{ pers.numerator }}</a>
                                </li>
                            {% else %}
                                <li><a href="{% url 'index' pers.numerator %}">{{ pers.numerator }}</a></li>
                            {% endif %}
                        {% endfor %}

                        {% if articles.has_next %}
                            <li>
                                <a href="{% url 'index' articles.next_page_number %}" aria-label="Next">
                                    <span aria-hidden="true">&raquo;</span>
                                </a>
                            </li>
                        {% else %}
                            <li><span aria-hidden="true" class="disabled">&raquo;</span></li>
                        {% endif %}
                    </ul>
                </nav>
            </div>
        </div>
    </div>
</div>

</body>
</html>